<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户答卷列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                          
                            
                            <li>
                                <label>用户：</label>
                                <input type="text" name="createBy"/>
                            </li>
                           
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
            
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:dajuan:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>

            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:dajuan:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:dajuan:remove')}]];

        var pingfenFlag = [[${@permission.hasAnyRoles('admin,user')}]];
        var userFlag = [[${@permission.hasRole('user')}]];
        var staffFlag = [[${@permission.hasRole('staff')}]];
        var prefix = ctx + "system/dajuan";
        var wprefix = ctx + "system/wenjuan";
        var pprefix = ctx + "system/pingfen";

        var pingfenprefix = ctx + "system/pingfen";
        var pid = getUrlParam('pid');
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                queryParams: queryParams,
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "用户答卷",
                pageSize:9999,
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                }, 
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                       return value=="0"?"未答题":"已答题";
                    }
                }, 
                {
                    field: 'score',
                    title: '分数'
                },
                {
                    field: 'rank',
                    title: '排名'
                },
                {
                    field: 'createBy',
                    title: '用户'
                },
                {
                    field: 'createTime',
                    title: '答题时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
						 
						if(row.status == 1){
							actions.push('<a class="btn btn-success btn-xs '+userFlag+'" href="javascript:void(0)" onclick="$.modal.openTab(\'查看\',\''+prefix+'/show/' + row.id + '\')"> 查看答题</a>  ');

							actions.push('<a class="btn btn-success btn-xs '+userFlag+' " href="javascript:void(0)" onclick="changeState(\'' + row.id + '\')">评分</a> ');
							actions.push('<a class="btn btn-success btn-xs '+pingfenFlag+' " href="javascript:void(0)" onclick="$.modal.openTab(\'查看\',\''+pingfenprefix+'?pid=' + row.id + '\')"> 查看评分</a>  ');
							
						} 
                         actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function queryParams(params) {
        	var search = $.table.queryParams(params);
        	search.wenjuanId =pid;
        	return search;
        }
        
        function changeState(id){
        	
        	layer.prompt({title: '请输入选手总分'}, function(text, index1){
        		 layer.close(index1);
        		layer.prompt({title: '请输入备注'}, function(text1, index2){
        			layer.close(index2);
            	    $.modal.confirm("确认操作？", function() {
                		$.operate.post(pprefix + "/add", { "pid": id, "score": text,"remark":text1 });
                	})
            	}); 
        	});
        }
    </script>
</body>
</html>